'use strict';

const ws = require("nodejs-websocket");
const _ = require('lodash');

let count = 0;
let textCount = 0;

const server = ws.createServer(function (conn) {
    count++;

    conn.on('text', function () {
        textCount ++;
    });

    conn.on('close', function () {
        count--;
    });

});

server.listen(8002);

console.log('server start');
setInterval(function () {
    console.log('server status', {
        count, textCount
    });
}, 1000);

setInterval(function () {
    _.each(server.connections, function (c) {
        c.sendText('hehe');
    });
}, 1234);
